/*
Created		14-03-12
Modified		21-03-12
Project		
Model		
Company		
Author		
Version		
Database		Oracle 10g 
*/


Drop table "LB_TCARRITO"
/
Drop table "LB_TPEDIDO"
/
Drop table "LB_TEDITORIAL"
/
Drop table "LB_TPERFIL"
/
Drop table "LB_TAUTOR"
/
Drop table "LB_TCATEGORIA"
/
Drop table "LB_TLIBRO"
/
Drop table "LB_TUSUARIO"
/


-- Create Types section


-- Create Tables section


Create table "LB_TUSUARIO" (
	"USER_ID" Number NOT NULL ,
	"USER_PERF_ID" Number NOT NULL ,
	"USER_NAME" Varchar2 (30) NOT NULL ,
	"USER_USER" Varchar2 (30) NOT NULL ,
	"USER_PASS" Varchar2 (30) NOT NULL ,
	"USER_DIR" Varchar2 (100) NOT NULL ,
	"USER_TELE" Number NOT NULL ,
primary key ("USER_USER") 
) 
/

Create table "LB_TLIBRO" (
	"LIBRO_ID" Number NOT NULL ,
	"LIBRO_AUTOR_ID" Number NOT NULL ,
	"LIBRO_CATE_ID" Number NOT NULL ,
	"LIBRO_EDIT_ID" Number NOT NULL ,
	"LIBRO_TITU" Varchar2 (200) NOT NULL ,
	"LIBRO_FEC_PUB" Date NOT NULL ,
	"LIBRO_EDIC" Varchar2 (30) NOT NULL ,
	"LIBRO_STOCK" Number NOT NULL ,
	"LIBRO_VALOR" Number NOT NULL ,
	"LIBRO_RESU" Varchar2 (200) NOT NULL ,
primary key ("LIBRO_ID") 
) 
/

Create table "LB_TCATEGORIA" (
	"CATE_ID" Number NOT NULL ,
	"CATE_NOMB" Varchar2 (30) NOT NULL ,
primary key ("CATE_ID") 
) 
/

Create table "LB_TAUTOR" (
	"AUTOR_ID" Number NOT NULL ,
	"AUTOR_NOMB" Varchar2 (30) NOT NULL ,
primary key ("AUTOR_ID") 
) 
/

Create table "LB_TPERFIL" (
	"PERF_ID" Number NOT NULL ,
	"PERF_NOMB" Varchar2 (30) NOT NULL ,
	"PERF_DESC" Varchar2 (200) NOT NULL ,
primary key ("PERF_ID") 
) 
/

Create table "LB_TEDITORIAL" (
	"EDIT_ID" Number NOT NULL ,
	"EDIT_NOMB" Varchar2 (30) NOT NULL ,
primary key ("EDIT_ID") 
) 
/

Create table "LB_TPEDIDO" (
	"PEDI_NRO" Number NOT NULL ,
	"PEDI_LIBRO_ID" Number NOT NULL ,
	"PEDI_RENGLN" Number NOT NULL ,
	"PEDI_ESTA" Varchar2 (30) NOT NULL ,
	"PEDI_UNID" Number NOT NULL ,
	"USER_USER" Varchar2 (30) NOT NULL ,
primary key ("PEDI_NRO") 
) 
/

Create table "LB_TCARRITO" (
	"CAR_ID" Number NOT NULL ,
	"CAR_LIBRO_ID" Number NOT NULL ,
	"CAR_RENGLN" Number NOT NULL ,
	"CAR_UNID" Number NOT NULL ,
	"USER_USER" Varchar2 (30) NOT NULL ,
primary key ("CAR_ID","USER_USER") 
) 
/


-- Create Alternate keys section


-- Create Indexes section


-- Create Foreign keys section

Alter table "LB_TPEDIDO" add  foreign key ("USER_USER") references "LB_TUSUARIO" ("USER_USER") 
/

Alter table "LB_TCARRITO" add  foreign key ("USER_USER") references "LB_TUSUARIO" ("USER_USER") 
/

Alter table "LB_TPEDIDO" add  foreign key ("PEDI_LIBRO_ID") references "LB_TLIBRO" ("LIBRO_ID") 
/

Alter table "LB_TCARRITO" add  foreign key ("CAR_LIBRO_ID") references "LB_TLIBRO" ("LIBRO_ID") 
/

Alter table "LB_TLIBRO" add  foreign key ("LIBRO_CATE_ID") references "LB_TCATEGORIA" ("CATE_ID") 
/

Alter table "LB_TLIBRO" add  foreign key ("LIBRO_AUTOR_ID") references "LB_TAUTOR" ("AUTOR_ID") 
/

Alter table "LB_TUSUARIO" add  foreign key ("USER_PERF_ID") references "LB_TPERFIL" ("PERF_ID") 
/

Alter table "LB_TLIBRO" add  foreign key ("LIBRO_EDIT_ID") references "LB_TEDITORIAL" ("EDIT_ID") 
/


-- Create Object Tables section


-- Create XMLType Tables section


-- Create Procedures section


-- Create Functions section


-- Create Views section


-- Create Sequences section


-- Create Triggers from referential integrity section


-- Create user Triggers section


-- Create Packages section


-- Create Synonyms section


-- Create Roles section


-- Users Permissions to roles section


-- Roles Permissions section

/* Roles permissions */


-- User Permissions section

/* Users permissions */


-- Create Table comments section

Comment on table "LB_TUSUARIO" is 'Usuarios del Sistema'
/
Comment on table "LB_TLIBRO" is 'Libros'
/
Comment on table "LB_TCATEGORIA" is 'Categorias de libros'
/
Comment on table "LB_TAUTOR" is 'Autores de Libros'
/
Comment on table "LB_TPERFIL" is 'Perfiles de Usuario'
/
Comment on table "LB_TEDITORIAL" is 'Editoriales'
/
Comment on table "LB_TPEDIDO" is 'Pedidos realizados por los clientes'
/
Comment on table "LB_TCARRITO" is 'Tabla temporal para almacenar los libros que comprara el cliente'
/

-- Create Attribute comments section

Comment on column "LB_TUSUARIO"."USER_ID" is 'Codigo del usuario'
/
Comment on column "LB_TUSUARIO"."USER_NAME" is 'Nombre real del Usuario'
/
Comment on column "LB_TUSUARIO"."USER_USER" is 'Usuario de acceso'
/
Comment on column "LB_TUSUARIO"."USER_PASS" is 'Password de Acceso'
/
Comment on column "LB_TUSUARIO"."USER_DIR" is 'Direccion Postal'
/
Comment on column "LB_TUSUARIO"."USER_TELE" is 'Telefono Usuario'
/
Comment on column "LB_TLIBRO"."LIBRO_TITU" is 'Titulo del libro'
/
Comment on column "LB_TLIBRO"."LIBRO_FEC_PUB" is 'Fecha de Publicacion'
/
Comment on column "LB_TLIBRO"."LIBRO_EDIC" is 'Edicion del Libro'
/
Comment on column "LB_TLIBRO"."LIBRO_STOCK" is 'Cantidad en Stock'
/
Comment on column "LB_TLIBRO"."LIBRO_VALOR" is 'Precio del Libro'
/
Comment on column "LB_TLIBRO"."LIBRO_RESU" is 'Resumen del contenido del libro'
/
Comment on column "LB_TCATEGORIA"."CATE_ID" is 'Codigo de la Categoria'
/
Comment on column "LB_TCATEGORIA"."CATE_NOMB" is 'Nombre de la Categoria'
/
Comment on column "LB_TAUTOR"."AUTOR_ID" is 'Codigo del Autor'
/
Comment on column "LB_TAUTOR"."AUTOR_NOMB" is 'Nombre del Autor'
/
Comment on column "LB_TPERFIL"."PERF_ID" is 'Codigo del Perfil'
/
Comment on column "LB_TPERFIL"."PERF_NOMB" is 'Nombre del Perfil'
/
Comment on column "LB_TPERFIL"."PERF_DESC" is 'Descripcion del Perfil'
/
Comment on column "LB_TEDITORIAL"."EDIT_ID" is 'Codigo de la Editorial'
/
Comment on column "LB_TEDITORIAL"."EDIT_NOMB" is 'Nombre de la Editorial'
/
Comment on column "LB_TPEDIDO"."PEDI_NRO" is 'Numero del Pedido'
/
Comment on column "LB_TPEDIDO"."PEDI_RENGLN" is 'Renglon del Pedido'
/
Comment on column "LB_TPEDIDO"."PEDI_ESTA" is 'Estado del Pedido (ES-Espera, SV- Servicio, EN - Enviado, CF - a Confirmar)'
/
Comment on column "LB_TPEDIDO"."PEDI_UNID" is 'Numero de Unidades compradas.'
/
Comment on column "LB_TCARRITO"."CAR_ID" is 'Id del carrito actual del cliente'
/
Comment on column "LB_TCARRITO"."CAR_RENGLN" is 'Renglon del pedido'
/
Comment on column "LB_TCARRITO"."CAR_UNID" is 'Cantidad de articulos'
/

-- After section


